package cn.wolfcode.car.base.service.impl;

import cn.wolfcode.car.base.domain.Customer;
import cn.wolfcode.car.base.mapper.CustomerMapper;
import cn.wolfcode.car.base.query.CustomerQuery;
import cn.wolfcode.car.base.service.ICustomerService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.util.Convert;
import cn.wolfcode.car.common.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public TablePageInfo<Customer> query(CustomerQuery qo) {
        // 分页信息
        Page<Customer> page = new Page<>(qo.getPageNum(), qo.getPageSize());
        // 过滤信息
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(qo.getName()), "name", qo.getName())
                .like(StringUtils.isNotEmpty(qo.getPhone()), "phone", qo.getPhone());
        return new TablePageInfo<>(super.page(page, wrapper).getRecords());
    }

}
